package com.thl.process;

import com.thl.common.MyExcetion;
import com.thl.common.enums.ErrorCodeEnum;
import com.thl.dto.RequestDto;
import com.thl.dto.ServiceContext;

/**
 * @author 1900614@qq.com
 * @version 1.0
 * @date 2021/6/19 19:50
 */
public abstract class AbstractExecuteService<K extends  RequestDto> {

    public final RequestDto execute(K request){
        if(null==request.getBusinessScene()){
            throw new MyExcetion(ErrorCodeEnum.STU_CONTEXT_PARAM_ERROR,"businessScene 不能为空");
        }
        ServiceContext serviceContext = new ServiceContext();
        serviceContext.setBusinessScene(request.getBusinessScene());
        doExecute(serviceContext);

        return  request;
    }

    protected  void doExecute(ServiceContext serviceContext){
        execute(serviceContext);
    }

    //交给具体的实现类
    protected abstract void execute(ServiceContext serviceContext);

}
